<template>
  <div>
    <div @keyup.enter="getData()">
      <el-form class="query-table-form" :inline="true">
        <el-form-item>
          <el-input v-model="params.customer_name" placeholder="项目名称查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="params.corp_name"
            placeholder="负责人查询"
            :clearable="true"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <select-address
            v-model="params.address_code"
            clearable
            placeholder="地址查询"
            :auto-top="true"
            @change="getData()"
          ></select-address>
        </el-form-item>
        <el-form-item>
          <el-button @click="getData()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="exportExcel(fileName)" :loading="exportLoading">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="tableData"
      :height="dialogHeight"
    ></c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <register-edit-dialog
      :visible.sync="approvalVisible"
      :viewModel="viewModel"
      @success="handleEditSuccess"
      :relatedData="formData"
    ></register-edit-dialog>
  </div>
</template>

<script>
import { enumProjectType } from '@/gov/plugins/enum'
import taskTableMixin from '@/credit/mixin/task/taskTable'
import RegisterEditDialog from '@/bank/views/mission/RegisterEditDialog'
import SelectAddress from '@/components/select/SelectAddress'
import { addressCut } from '@vimi/utils-tool'
export default {
  components: {
    RegisterEditDialog,
    SelectAddress,
  },
  mixins: [taskTableMixin],
  props: {
    visible: Boolean,
  },
  data() {
    return {
      enumProjectType,
      order: {},
      params: {
        index: 1,
        size: 10,
      },
      totalCount: 0,
      viewModel: false,
      tableData: [],
      tableColumns: [
        {
          attrs: { label: '主体名称', prop: 'customer_name', align: 'center' },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '地址', prop: 'address', align: 'center' } },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
        { attrs: { label: '项目类型', prop: 'projectType', align: 'center' } },
        {
          attrs: { label: '操作', align: 'center' },
          operations: [
            { name: '登记', event: this.handleEdit, ifRender: row => +row.task_status === 0 },
            { name: '查看', event: this.handleEdit, ifRender: row => +row.task_status === 1 },
          ],
        },
      ],
      approvalVisible: false,
      formData: {},
    }
  },
  computed: {
    fileName() {
      if (+this.status === 0) {
        return '未登记项目'
      } else {
        return '已登记项目'
      }
    },
  },
  watch: {},
  mounted() {},
  created() {
    if (+this.status === 0) {
      this.order = { claim_time: 'desc' }
    } else {
      this.order = { bank_approved_time: 'desc' }
    }
    this.params['task_type.eq'] = this.type
    this.params['task_status.eq'] = this.status
    this.params['orWhereAnd.address_code.endlike'] = addressCut(this.$utils.getAddressCode())
    this.params['orWhereAnd.task_person.eq'] = 'all'
    this.params['orWhereAnd.task_person.like'] = this.clientId
    this.params['orWhereAnd.customer_related_id.neq'] = '1'
  },
  methods: {
    getParams() {
      return this.params
    },
    handleEdit(row) {
      this.viewModel = +row.task_status === 1
      this.formData = row ? { ...row } : {}
      this.approvalVisible = true
    },
    dataAdapter(item) {
      item.projectType = enumProjectType[item.project_type] || '-'
      return item
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handleEditSuccess() {
      this.$store.dispatch('getMyTaskCount')
      this.$emit('success', true)
    },
  },
}
</script>
<style lang="scss" scoped></style>
